<?php

/**
 * 
 * @author Administrator
 *
 */
class SkillService extends Service{

    public static function indexHeader(){
        return array(
        		'id'         => array('text' => 'ID', 'rule' => 'int'),
        		's_id'       => array('text' => '技能标识'),
        		'name'       => array('text' => '技能名称'), 
        		'posture'    => array('text' => '技能姿态'), 
        		'type'       => array('text' => '技能类型'),
        		'shape'      => array('text' => '技能形状样式'),
        		'description'=> array('text' => '技能描述'),
        		'backstage_show'      => array('text' => '后台是否显示'),
        		'backstage_type'      => array('text' => '技能分类'),
        		'backstage_level'     => array('text' => '技能等级'),
                'action'     => array('text' => '操作')
        );
    }
    
    public static function indexData($params){
    	$modSkill = new ModSkill();
    	$result = $modSkill->page($params); 
    	
    	$postureList = self::postureList();
    	$shapeList = self::shapeList();
    	$typeList = self::typeList();
    	foreach($result['data'] as &$v){ 
    		if($v['backstage_show'] == 0){
    			$backstage_show = '否';
    		}
    		if($v['backstage_show'] == 1){
    			$backstage_show = '是';
    		}
    		$v['backstage_show'] = $backstage_show;
    		$v['posture'] = $postureList[$v['posture']];
    		$v['shape'] = $shapeList[$v['shape']];
    		$v['type'] = $typeList[$v['type']];
    		$v['action']   .= ' <a href="'.PubFunc::buildUrl('/oss/?r=skill/delete').'&id='.$v['id'].'" confirm="是否要删除该条信息?">删除</a>';
    	}
    	unset($v);
    	return $result;
    }
    
    public static function postureList(){
    	return array(
    			'0' => '无效',
    			'1' => '主动',
    			'2' => '变身'
    	);
    }
    
    public static function shapeList(){
    	return array(
    			'0' => '无',
    			'1' => '扇形',
    			'2' => '矩形'
    	);
    }
    
    public static function typeList(){
    	return array(
    			'0' => '无效',
    			'11' => '出售',
    			'12' => '死亡',
    			'13' => '复活',
    			'101' => '站立',
    			'102' => '转身',
    			'103' => '移动',
    			'106' => '骑乘（站立）',
    			'107' => '骑乘（转身）',
    			'108' => '骑乘（移动）',
    			'111' => '跳跃',
    			'112' => '飞跃',
    			'116' => '传送',
    			'121' => '上马',
    			'122' => '下马',
    			'131' => '采集',
    			'201' => '受击',
    			'501' => '普通攻击',
    			'502' => '技能攻击',
    			'511' => '冲刺攻击',
    			'1001' => '被动',
    			'2001' => '技能强化',
    			'3001' => '永久加成',
    	);
    }
    
    
    
    
    public static function delete($id){
    	if(empty($id)) return false;
    
    	$modSkill = new ModSkill();
    	$modSkill->deleteByPk($id);
    	return true;
    }
    
    public static function upload($files){
    	$file = new PubFile();
    	$fileName = $files["file"]["name"];
    	$suffixArr = array('xls','xlsx','xlsm'); //允许上传的文件后缀
    	$check= $file::checkSuffix($fileName,$suffixArr);
    	if($check){
    		$ext = $file::getSuffix($fileName);
    		$uploadDir = '../public/upload/skill/'.date('Ym').'/';
    		$uploadName = md5(microtime(true)).'.'.$ext;
    		$upload = $file::uploadFile($files["file"],$uploadDir,$uploadName);
    		if(!$upload){
    			return array('status' => 0, 'msg' =>$upload,'data'=>'');
    		}else{
    			$path = dirname(dirname(dirname(dirname(__File__)))).'/public/upload/skill/'.date('Ym').'/'.$uploadName;  //获取绝对路径
    			return array('status' => 1, 'msg' =>'上传成功','data'=>$path);
    		}
    	}else{
    		return array('status' => 0, 'msg' =>'上传文件后缀不允许!','data'=>'');
    	}
    }
    
    public static function xlsAdd($data){
    	$modSkill = new ModSkill();
    	unset($data[1]);
    	unset($data[2]);
    	unset($data[3]);
    	unset($data[4]);
    	
    	$add_data = array();
    	$gid_array = $modSkill->getGid();
    	
    	$gid_in = array();
    	foreach ($gid_array as $key=>$val){
    		$gid_in[] = $val['s_id'];
    	}
    	$game = PubBase::getCurrentGame();
        $all_num = count($data);
        $success_num = 0;
        $error_num = 0;
    	foreach($data as $v){
    		if(in_array($v['A'], $gid_in)){  //已经存在
    			$error_num++;
    			continue;
    		}
    		$d = array();
    		$d['game'] = $game;
    		$d['s_id'] = $v['A'];
    		$d['name'] = $v['B'];
    		$d['description'] = $v['C'];
    		$d['posture'] = $v['D'];
    		$d['type'] = $v['E'];
    		$d['subtype'] = $v['F'];
    		$d['shape'] = $v['G'];
    		$d['cooling_time'] = $v['H'];
    		$d['mask_interrupted'] = $v['I'];
    		$d['action_id'] = $v['J'];
    		$d['attribute_id'] = $v['K'];
    		$d['damage_power'] = $v['L'];
    		$d['area_effect_limit'] = $v['M'];
    		$d['hit_buff_list'] = $v['N'];
    		
    		$d['activation_type'] = $v['O'];
    		$d['activation_breakpoint'] = $v['P'];
    		$d['activation_value'] = $v['Q'];
    		$d['activation_probability'] = $v['R'];
    		$d['activation_cond_list'] = $v['S'];   		
    		
    		$d['slot_index'] = $v['T'];
    		$d['offset_distance'] = $v['U'];
    		$d['offset_angle'] = $v['V'];
    		$d['orientation_angle'] = $v['W'];
    		$d['cope_param1'] = $v['X'];
    		$d['scope_param2'] = $v['Y'];
    		$d['icon_resource_id'] = $v['Z'];
    		$d['skill_name_id'] = $v['AA'];
    		$d['hearsay_id'] = $v['AB'];
    		$d['backstage_show'] = $v['AC'];
    		$d['backstage_type'] = $v['AD'];
    		$d['backstage_level'] = $v['AE'];
    		

    		array_push($add_data, $d);
    	}
    	$success_num = $all_num - $error_num;
    	$msg = '导入成功 '.$success_num.' 条，失败 '.$error_num.' 条';
    	$result = $modSkill->addmuch($add_data);
    	return array('status' => 1, 'msg' =>$msg,'data'=>'');
    }
    
    

    
}